package com.vodone.v1pin.user.delegate
{
	
	import com.vodone.v1pin.ServiceProvider;
	import com.vodone.v1pin.core.model.MainModelLocator;
	import com.vodone.v1pin.core.service.HttpJsonDelegate;
	
	import flash.external.ExternalInterface;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	
	import mx.rpc.http.mxml.HTTPService;
	
	[Bindable]
	public class UserBagDelegate
	{
		/**
		 * 获取购物袋商品 
		 * @param resultHandler
		 * @param list
		 * @param faultHandler
		 * @param context
		 * 
		 */		  
		public static function getBagGoods( resultHandler:Function , list:Array, faultHandler:Function = null , context:Array = null ):void
		{
			var service:HTTPService = ServiceProvider.getInstance().getBagGoodsService;
			var params:Object = {
				myGoodsList  : list
			}
			
			var delegate:HttpJsonDelegate = new HttpJsonDelegate( service );
			delegate.send( params , resultHandler , faultHandler , context );
		}
		
		/**
		 * 生成订单 
		 * @param resultHandler
		 * @param json
		 * @param faultHandler
		 * @param context
		 * 
		 */		
		public static function creatOrder( resultHandler:Function , json:String, faultHandler:Function = null , context:Array = null ):void
		{
			var service:HTTPService = ServiceProvider.getInstance().creatOrderService;
			var params:Object = {
				json  : json
			}
			
			var delegate:HttpJsonDelegate = new HttpJsonDelegate( service );
			delegate.send( params , resultHandler , faultHandler , context );
		}
		/**
		 * 支付 方式
		 * @param resultHandler
		 * @param list
		 * @param faultHandler
		 * @param context
		 * 
		 */		
		public static function payOrder( resultHandler:Function , ordernum:String , ordertype:String , orderpay:String , faultHandler:Function = null , context:Array = null ):void
		{
			var service:HTTPService = ServiceProvider.getInstance().orderPayService;
			var params:Object = {
				ordernum  : ordernum,
				ordertype  : ordertype,
				orderpay  : orderpay
			}
			
			var delegate:HttpJsonDelegate = new HttpJsonDelegate( service );
			delegate.send( params , resultHandler , faultHandler , context );
		}
		
		/**
		 * 支付 
		 * @param resultHandler
		 * @param list
		 * @param faultHandler
		 * @param context
		 * 
		 */		
		public static function payFinalOrder( resultHandler:Function , ordernum:String , ordertype:String , orderpay:String , bankCode:String , faultHandler:Function = null , context:Array = null ):void
		{
			
			
			
			var url:String = MainModelLocator.getInstance().config.infoUrl + "/testHandler.ashx";
			if( bankCode == "" ){
				url += "?ordernum=" + ordernum + "&ordertype=" + ordertype + "&orderpay=" + orderpay;
			}else{
				url += "?ordernum=" + ordernum + "&ordertype=" + ordertype + "&orderpay=" + orderpay + "&bankCode=" + bankCode;
			}
			//			url += "?ordernum=" + "1054111101730" + "&ordertype=" + "2";
			var request:URLRequest=new URLRequest(url);  
			
//			ExternalInterface.call("openwin",url);
			
			navigateToURL(request,"_blank");  
			
			/*var service:HTTPService = ServiceProvider.getInstance().payService;
			var params:Object = {
				ordernum  : ordernum,
				ordertype  : ordertype
			}
			
			var delegate:HttpJsonDelegate = new HttpJsonDelegate( service );
			delegate.send( params , resultHandler , faultHandler , context );*/
		}
		
		/**
		 * 判断支付是否成功 
		 * @param resultHandler
		 * @param list
		 * @param faultHandler
		 * @param context
		 * 
		 */		
		public static function checkOrderResult( resultHandler:Function , ordernum:String, faultHandler:Function = null , context:Array = null ):void
		{
			var service:HTTPService = ServiceProvider.getInstance().checkPayResultService;
			var params:Object = {
				ordernum  : ordernum
			}
			
			var delegate:HttpJsonDelegate = new HttpJsonDelegate( service );
			delegate.send( params , resultHandler , faultHandler , context );
		}
		
		/**
		 * 判断商品库存 
		 * @param resultHandler
		 * @param list
		 * @param faultHandler
		 * @param context
		 * 
		 */		  
		public static function getBagGoodsKC( resultHandler:Function , id:String, faultHandler:Function = null , context:Array = null ):void
		{
			var service:HTTPService = ServiceProvider.getInstance().getBagGoodsKCService;
			var params:Object = {
				goodsId : id
			}
			
			var delegate:HttpJsonDelegate = new HttpJsonDelegate( service );
			delegate.send( params , resultHandler , faultHandler , context );
		}
	}
}